package com.rhb.oa.news.web.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.*;

import org.apache.struts.action.*;

import com.rhb.oa.news.web.struts.form.NewsForm;
import com.rhb.oa.web.struts.action.OaBaseDispatchAction;


public class NewsViewAction extends OaBaseDispatchAction {

	public ActionForward unspecified(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		return list(mapping,form,request,response);
	}
	
	
	public ActionForward list(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){

		NewsForm eForm = (NewsForm)form;

		int allcount = this.getNewsBusiness().getAllCount_findByQuery(eForm.getNewsQuery());
		List list = null;
		if ( allcount != 0) {
			list = this.getNewsBusiness().findByQuery(eForm.getNewsQuery(),eForm.getStart(),eForm.getCount());
		}else{
			list = (List)new ArrayList();
		}

		eForm.setAllCount(allcount);
		eForm.setList(list);

		return mapping.findForward("list");
	}
	
	public ActionForward view(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		NewsForm oform = (NewsForm)form;
		oform.setNews(this.getNewsBusiness().findByPk(oform.getNews().getNewsPk()));
		return mapping.findForward("view");
	}
}
